import logging

import colorlog

logger = logging.getLogger("colorlog")


def init(color="auto"):
    handler = colorlog.StreamHandler()
    if color == "always" or color == "auto" and handler.stream.isatty():
        handler.setFormatter(
            colorlog.ColoredFormatter(
                "%(log_color)s[%(levelname)s]%(reset)s %(message)s",
                log_colors={
                    "DEBUG": "cyan",
                    "INFO": "green",
                    "WARNING": "yellow",
                    "ERROR": "red",
                    "CRITICAL": "bold_red,bg_white",
                },
            )
        )
    else:
        handler.setFormatter(logging.Formatter("[%(levelname)s] %(message)s"))
    logger.addHandler(handler)
    logger.setLevel(logging.INFO)
